import 'package:floor/floor.dart';
import 'package:share_fit/app/dao/dao_mixin.dart';
import 'package:share_fit/app/models/home/menstrual_mode.dart';

@dao
abstract class MenstrualDao with DaoMixin<MenstrualModel> {
  @override
  @Query('SELECT * FROM menstrual WHERE _id = :id')
  Stream<MenstrualModel?> findById(int id);

  @Query('SELECT * FROM menstrual where address = :address order by date_created desc limit 1')
  Future<MenstrualModel?> findLatestOne(String address);

  @override
  @Query('SELECT * FROM menstrual')
  Future<List<MenstrualModel>> findAll();

  @override
  @Query('SELECT * FROM menstrual')
  Stream<List<MenstrualModel>> findAllAsStream();

  @override
  @Query('delete FROM menstrual')
  Future<void> deleteAll();

  @Query('SELECT * FROM menstrual WHERE date_created >= :startTime and date_created < :endTime')
  Future<List<MenstrualModel>> findBy(int startTime, int endTime);

  @Query('delete FROM menstrual where address = :address')
  @override
  Future<void> deleteAllByAddress(String address);
}
